{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "int32\n",
      "int16\n",
      "int64\n",
      "[('name', 'S20'), ('age', 'i1'), ('marks', '<f4')]\n",
      "[(b'abc', 20, 61.) (b'xyz', 21, 69.) (b'uvw', 22, 89.)]\n",
      "[b'abc' b'xyz' b'uvw']\n",
      "[20 21 22]\n",
      "[61. 69. 89.]\n"
     ]
    }
   ],
   "source": [
    "# numpy 库\n",
    "#\n",
    "import numpy as np\n",
    "\n",
    "# NumPy 数据类型\n",
    "# bool_\t        布尔型数据类型（True 或者 False）\n",
    "# int_\t        默认的整数类型（类似于 C 语言中的 long，int32 或 int64）\n",
    "# intc\t        与 C 的 int 类型一样，一般是 int32 或 int 64\n",
    "# intp\t        用于索引的整数类型（类似于 C 的 ssize_t，一般情况下仍然是 int32 或 int64）\n",
    "# int8\t        字节（- 128 to 127）\n",
    "# int16\t        整数（- 32768 to 32767）\n",
    "# int32\t        整数（- 2147483648 to 2147483647）\n",
    "# int64\t        整数（- 9223372036854775808 to 9223372036854775807）\n",
    "# uint8\t        无符号整数（0 to 255）\n",
    "# uint16\t    无符号整数（0 to 65535）\n",
    "# uint32\t    无符号整数（0 to 4294967295）\n",
    "# uint64\t    无符号整数（0 to 18446744073709551615）\n",
    "# float_\t    float64 类型的简写\n",
    "# float16\t    半精度浮点数，包括：1 个符号位，5 个指数位，10 个尾数位\n",
    "# float32\t    单精度浮点数，包括：1 个符号位，8 个指数位，23 个尾数位\n",
    "# float64\t    双精度浮点数，包括：1 个符号位，11 个指数位，52 个尾数位\n",
    "# complex_\t    complex128 类型的简写，即 128 位复数\n",
    "# complex64\t    复数，表示双 32 位浮点数（实数部分和虚数部分）\n",
    "# complex128\t复数，表示双 64 位浮点数（实数部分和虚数部分）\n",
    "\n",
    "# 每个内建类型都有一个唯一定义它的字符代码，如下：\n",
    "# b     布尔型\n",
    "# i     (有符号) 整型\n",
    "# u\t    无符号整型 integer\n",
    "# f\t    浮点型\n",
    "# c\t    复数浮点型\n",
    "# m\t    timedelta（时间间隔）\n",
    "# M\t    datetime（日期时间）\n",
    "# O     (Python) 对象\n",
    "# S, a(byte-)字符串\n",
    "# U\t    Unicode\n",
    "# V\t    原始数据(void)\n",
    "\n",
    "# dtype 对象是使用以下语法构造的：\n",
    "# numpy.dtype(object, align, copy)\n",
    "# object    - 要转换为的数据类型对象\n",
    "# align     - 如果为 true，填充字段使其类似 C 的结构体。\n",
    "# copy      - 复制 dtype 对象 ，如果为 false，则是对内置数据类型对象的引用\n",
    "\n",
    "# 使用标量类型\n",
    "dt = np.dtype(np.int32)\n",
    "print(dt)\n",
    "# int8, int16, int32, int64 四种数据类型可以使用字符串 'i1', 'i2','i4','i8' 代替\n",
    "dt = np.dtype('i2')\n",
    "print(dt)\n",
    "# 字节顺序标注\n",
    "dt = np.dtype('<i8')\n",
    "print(dt)\n",
    "\n",
    "# 结构化数据类型\n",
    "dt_student = np.dtype([('name', 'S20'), ('age', np.int8), ('marks', 'f4')])\n",
    "print(dt_student)\n",
    "student = np.array([(\"abc\", 20, 61), ('xyz', 21, 69),\n",
    "             ('uvw', 22, 89)], dtype=dt_student)\n",
    "print(student)\n",
    "print(student['name'])\n",
    "print(student['age'])\n",
    "print(student['marks'])\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.9.9 64-bit",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.9 (tags/v3.9.9:ccb0e6a, Nov 15 2021, 18:08:50) [MSC v.1929 64 bit (AMD64)]"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "cf18841ace8313d0bc088ca146c17a6c0040e82121d5cb75c0ea07172309253d"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
